From d2c80fdf2aa2066a9abf099338d33b3b87f3f0f1 Mon Sep 17 00:00:00 2001 From: Ercan Erden Date: Sat, 13 Jun 2015 16:34:14 -0400 Subject: [PATCH] Improve autocompletion of test items Test item autocompletion didn't work because it required the name of the test to come immediately after [[test]] line. This commit should fix that. --- src/etc/_cargo | 61 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 42 insertions(+), 19 deletions(-) diff --git a/src/etc/_cargo b/src/etc/_cargo index f80a3211e..314b282ce 100644 --- a/src/etc/_cargo +++ b/src/etc/_cargo @@ -1,4 +1,5 @@ #compdef cargo + typeset -A opt_args autoload -U regexp-replace @@ -303,26 +304,48 @@ regexp-replace manifest '\{"root":"|"\}' '' echo $manifest } -#gets test names from the manifest file -_test_names(){ -local -a filelist; -local manifest=$(_locate_manifest) -if ! [[ $manifest ]]; then - return 0 -fi - -local last_line -local -a tests; -tests=() -while read line -do - if [[ $last_line == '[[test]]' ]]; then - regexp-replace line '^.*name *= *|"' "" - tests+=$line +# Extracts the values of "name" from the array given in $1 and shows them as +# command line options for completion +_get_names_from_array() +{ + local -a filelist; + local manifest=$(_locate_manifest) + if ! [[ $manifest ]]; then + return 0 fi - last_line=$line -done < $manifest -_describe 'tests' tests + + local last_line + local -a names; + local in_block=false + local block_name=$1 + names=() + while read line + do + if [[ $last_line == "[[$block_name]]" ]]; then + in_block=true + else + if [[ $last_line =~ '.*\[\[.*' ]]; then + in_block=false + fi + fi + + if [[ $in_block == true ]]; then + if [[ $line =~ '.*name.*=' ]]; then + regexp-replace line '^.*name *= *|"' "" + names+=$line + fi + fi + + last_line=$line + done < $manifest + _describe $block_name names + +} + +#Gets the test names from the manifest file +_test_names() +{ + _get_names_from_array "test" } _cargo -- 2.30.2